<template>
    <div class="app-container calendar-list-container" v-loading="loading" element-loading-text="正在导出数据">
    <!-- filter 条件查询 -->
    <div class="btn-add">
        <el-button
        icon="el-icon-circle-plus-outline"
        type="button"
        class="el-button el-button--primary"
        @click="addclick"
        >
            新增</el-button
        >
    </div>

    <!-- 新增数据弹窗 -->
    <el-dialog
      :title="title"
      :visible.sync="showAdd"
      @close="alterClose"
      width="80%"
    >
        <el-form :model="createForm" ref="createForm" :rules="addRules" label-width="120px">
          <el-row :gutter="0">
            <el-col :span="6">
              <el-form-item label="资源大类" prop="facilityBarcodeType1" label-width="80px" >
                <el-select
                    v-model="createForm.facilityBarcodeType1"
                    class="ul-item"
                    filterable
                    clearable
                    @focus="getBarcodeType('大类')">
                    <el-option
                        v-for="(item,index) in barcodeType1List"
                        :key="index"
                        :label="item.facilityBarcodeName"
                        :value="item.facilityBarcodeName">
                    </el-option>
                </el-select>
                  <!-- <el-input clearable v-model.trim="createForm.facilityBarcodeType1" class="ul-item" /> -->
              </el-form-item>
              <el-form-item label="资源编码" prop="facilityCoding" label-width="80px" >
                  <el-input clearable v-model.trim="createForm.facilityCoding" class="ul-item" />
              </el-form-item>
              <el-form-item label="验收记录" prop="inspectionReport" label-width="80px" >
                <el-upload
                class="avatar-uploader"
                action="http://192.168.3.11:8086/technologyFile"
                :on-success="handlePdfSuccess"
                :on-remove = "removePdf"
                :on-change= "pdfRemove"
                :headers="getHttpHeader"
                :before-upload="beforeFilsUpload">
                <!-- object标签用于包含对象，比如图像、音频、视频、java applets、ActiveX、PDF以及Flash -->
                <el-button v-if="fileBool" size="small" type="primary">点击上传</el-button>
                <!-- <div>{{ createForm.inspectionReport }}</div> -->
                </el-upload>
                  <!-- <el-input clearable v-model.trim="createForm.inspectionReport" class="ul-item" /> -->
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="资源小类" prop="facilityBarcodeType2" >
                <el-select
                    v-model="createForm.facilityBarcodeType2"
                    class="ul-item"
                    filterable
                    clearable
                    @focus="getBarcodeType('小类')">
                    <el-option
                        v-for="(item,index) in barcodeType2List"
                        :key="index"
                        :label="item.facilityBarcodeName"
                        :value="item.facilityBarcodeName">
                    </el-option>
                </el-select>
                  <!-- <el-input  clearable v-model.trim="createForm.facilityBarcodeType2" class="ul-item" /> -->
              </el-form-item>
              <el-form-item label="工作中心" prop="workCenter" >
                <el-select  clearable filterable v-model="createForm.workCenter" placeholder="请选择工作中心" @change="changeworkCenter" @focus="getCenterList" class="ul-item">
                  <el-option :value="item" :label="item" v-for="(item,index) in this.centerList.data" :key="index"/>
                </el-select>
                <el-link :underline="false" type="danger">请先选择工作中心在填写大类/小类</el-link>
              </el-form-item>
              <el-form-item label="管理员" prop="userName" >
                <div style="display: flex">
                    <el-select style="width: 130px;" clearable filterable v-model="createForm.userName" placeholder="姓名" @change="changeName" @focus="getuserList" class="ul-item">
                      <el-option :value="item.userName" :label="item.userName" v-for="(item,index) in this.userList" :key="index"/>
                    </el-select>
                    <el-select style="width: 130px;" clearable filterable v-model="createForm.jobNumber" placeholder="工号" @change="changejobNumber" @focus="getuserList" class="ul-item">
                      <el-option :value="item.jobNumber" :label="item.jobNumber" v-for="(item,index) in this.userList" :key="index"/>
                    </el-select>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="资源规格" prop="facilityBarcodeType3" >
                <el-select
                    filterable
                    clearable
                    v-model="createForm.facilityBarcodeType3"
                    class="ul-item"
                    @focus="getBarcodeType('规格')">
                    <el-option
                        v-for="(item,index) in barcodeType3List"
                        :key="index"
                        :label="item.facilityBarcodeName"
                        :value="item.facilityBarcodeName">
                    </el-option>
                </el-select>
                  <!-- <el-input clearable v-model.trim="createForm.facilityBarcodeType3" class="ul-item" /> -->
              </el-form-item>
              <el-form-item label="库房位置" prop="warehouseLocation" >
                <el-select clearable v-model="createForm.warehouseLocation" placeholder="请选择库房位置" class="ul-item">
                    <el-option v-for="(item,index) in placeList" :key="index" :label="item" :value="item" />
                </el-select>
              </el-form-item>
              <el-form-item label="出入库审核" prop="accessAudit" > 
                  <el-switch  v-model="createForm.accessAudit" active-value="是" inactive-value="否" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="资源名称" prop="facilityName" >
                  <el-input clearable v-model.trim="createForm.facilityName" class="ul-item" />
              </el-form-item>
              <el-form-item label="来源属性" prop="resourceSource" >
                <el-select clearable v-model="createForm.resourceSource" placeholder="请选择属性" class="ul-item">
                    <el-option v-for="(item,index) in propertyList" :key="index" :label="item" :value="item" />
                </el-select>
              </el-form-item>
              <el-form-item label="生产或购置日期" prop="facilityProductionDate" >
                <el-date-picker clearable v-model="createForm.facilityProductionDate" value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" class="ul-item" />
                  <!-- <el-input v-model.trim="createForm.facilityProductionDate" class="ul-item" /> -->
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="0">
            <el-col :span="2">
                <el-form-item label="点检审核" prop="spotAudit" label-width="80px" >    
                    <el-switch  v-model="createForm.spotAudit" active-value="是" inactive-value="否" />
              </el-form-item>
                <el-form-item label="校验审核" prop="verifyAudit" label-width="80px" >
                    <el-switch  v-model="createForm.verifyAudit" active-value="是" inactive-value="否" />
                </el-form-item>
                <el-form-item label="外校审核" prop="externalSchoolAudit" label-width="80px" >
                    <el-switch  v-model="createForm.externalSchoolAudit" active-value="是" inactive-value="否" />
                </el-form-item> 
                <el-form-item label="保养审核" prop="maintenanceAudit" label-width="80px" >
                    <el-switch  v-model="createForm.maintenanceAudit" active-value="是" inactive-value="否" />
                </el-form-item>
            </el-col>
            <el-col :span="2">
                <el-form-item label="是否点检" prop="isSpot" label-width="70px">
                    <el-switch  v-model="createForm.isSpot" active-value="是" inactive-value="否" />
                </el-form-item>
                <el-form-item label="是否校验" prop="isVerify" label-width="70px" >
                    <el-switch  v-model="createForm.isVerify" active-value="是" inactive-value="否" />
                </el-form-item>
                <el-form-item label="是否外校" prop="isExternalSchool" label-width="70px" >
                    <el-switch  v-model="createForm.isExternalSchool" active-value="是" inactive-value="否" />
                </el-form-item>
                <el-form-item label="是否保养" prop="isMaintenance" label-width="70px" >
                    <el-switch  v-model="createForm.isMaintenance" active-value="是" inactive-value="否" />
                </el-form-item>
            </el-col>
            <el-col :span="7">
                <div style="height: 45px;">
                    <el-form-item label="点检频次" prop="spotFrequency" label-width="70px" v-if="createForm.isSpot == '是'">
                        <!-- {{ '每' }} -->
                        <el-popover v-model="cronspot">
                            <cron @change="changespot($event,'1')" @close="cronspot=false" i18n="cn"></cron>
                            <el-input clearable style="width: 130px;margin: 0 3px 0 6px;" slot="reference" @click="cronspot=true" v-model="createForm.spotFrequency" placeholder="请输入定时策略"></el-input>
                        </el-popover> {{ '或' }}    
                        <!-- spotCumulativeNumber  检点积累次数 -->
                        <el-input clearable style="width: 80px;margin: 0 3px 0 6px;" v-model.trim="createForm.spotUpperLimitNumber" class="ul-item" /> {{ '次 &nbsp;执行一次' }}
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <el-form-item label="校验频次" prop="verifyFrequency" label-width="70px" v-if="createForm.isVerify == '是'">
                        <!-- {{ '每' }} -->
                        <el-popover v-model="cronverify">
                            <cron @change="changeverify($event,'1')" @close="cronverify=false" i18n="cn"></cron>
                            <el-input clearable style="width: 130px;margin: 0 3px 0 6px;" slot="reference" @click="cronverify=true" v-model="createForm.verifyFrequency" placeholder="请输入定时策略"></el-input>
                        </el-popover> {{ '或' }}    
                        <!-- verifyCumulativeNumber 校验积累次数 -->
                        <el-input clearable style="width: 80px;margin: 0 3px 0 6px;" v-model.trim="createForm.verifyUpperLimitNumber" class="ul-item" /> {{ '次 &nbsp;执行一次' }}
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <el-form-item label="外校频次" prop="externalSchoolFrequency" label-width="70px" v-if="createForm.isExternalSchool == '是'" >
                        <!-- {{ '每' }} -->
                        <el-popover v-model="cronexternal">
                            <cron @change="changeexternal($event,'1')" @close="cronexternal=false" i18n="cn"></cron>
                            <el-input clearable style="width: 130px;margin: 0 3px 0 6px;" slot="reference" @click="cronexternal=true" v-model="createForm.externalSchoolFrequency" placeholder="请输入定时策略"></el-input>
                        </el-popover> {{ '或' }}    
                        <!-- externalSchoolCumulativeNumber 外校积累次数  -->
                        <el-input clearable style="width: 80px;margin: 0 3px 0 6px;" v-model.trim="createForm.externalSchoolUpperLimitNumber" class="ul-item" /> {{ '次 &nbsp;执行一次' }}
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <el-form-item label="保养频次" prop="maintenanceFrequency" label-width="70px" v-if="createForm.isMaintenance == '是'" >
                        <!-- {{ '每' }} -->
                        <el-popover v-model="cronmaintenance">
                            <cron @change="changemaintenance($event,'1')" @close="cronmaintenance=false" i18n="cn"></cron>
                            <el-input clearable style="width: 130px;margin: 0 3px 0 6px;" slot="reference" @click="cronmaintenance=true" v-model="createForm.maintenanceFrequency" placeholder="请输入定时策略"></el-input>
                        </el-popover> {{ '或' }}    
                        <!-- maintenanceCumulativeNumber 保养积累次数  -->
                        <el-input clearable style="width: 80px;margin: 0 3px 0 6px;" v-model.trim="createForm.maintenanceUpperLimitNumber" class="ul-item" /> {{ '次 &nbsp;执行一次' }}
                    </el-form-item>
                </div>
                </el-col>
                <el-col :span="7">
                <div style="height: 45px;">
                    <el-form-item label="提醒频次" prop="spotRemindFrequency" label-width="80px" v-if="createForm.isSpot == '是'">
                        <!-- {{ '每' }} -->
                        <el-popover v-model="cronspot1">
                            <cron @change="changespot($event,'2')" @close="cronspot1=false" i18n="cn"></cron>
                            <el-input clearable style="width: 130px;margin: 0 3px 0 6px;" slot="reference" @click="cronspot1=true" v-model="createForm.spotRemindFrequency" placeholder="请输入定时策略"></el-input>
                        </el-popover> {{ '或' }}    
                        <!-- spotCumulativeNumber  检点积累次数 -->
                        <el-input clearable style="width: 80px;margin: 0 3px 0 6px;" v-model.trim="createForm.spotRemindUpperFrequencyLimit" class="ul-item" /> {{ '%邮件提醒' }}
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <el-form-item label="提醒频次" prop="verifyRemindFrequency" label-width="80px" v-if="createForm.isVerify == '是'">
                        <!-- {{ '每' }} -->
                        <el-popover v-model="cronverify2">
                            <cron @change="changeverify($event,'2')" @close="cronverify2=false" i18n="cn"></cron>
                            <el-input clearable style="width: 130px;margin: 0 3px 0 6px;" slot="reference" @click="cronverify2=true" v-model="createForm.verifyRemindFrequency" placeholder="请输入定时策略"></el-input>
                        </el-popover> {{ '或' }}    
                        <!-- verifyCumulativeNumber 校验积累次数 -->
                        <el-input clearable style="width: 80px;margin: 0 3px 0 6px;" v-model.trim="createForm.verifyRemindUpperFrequencyLimit" class="ul-item" /> {{ '%邮件提醒' }}
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <el-form-item label="提醒频次" prop="externalSchoolRemindFrequency" label-width="80px" v-if="createForm.isExternalSchool == '是'" >
                        <!-- {{ '每' }} -->
                        <el-popover v-model="cronexternal3">
                            <cron @change="changeexternal($event,'2')" @close="cronexternal3=false" i18n="cn"></cron>
                            <el-input clearable style="width: 130px;margin: 0 3px 0 6px;" slot="reference" @click="cronexternal3=true" v-model="createForm.externalSchoolRemindFrequency" placeholder="请输入定时策略"></el-input>
                        </el-popover> {{ '或' }}    
                        <!-- externalSchoolCumulativeNumber 外校积累次数  -->
                        <el-input clearable style="width: 80px;margin: 0 3px 0 6px;" v-model.trim="createForm.externalSchoolRemindUpperFrequencyLimit" class="ul-item" /> {{ '%邮件提醒' }}
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <el-form-item label="提醒频次" prop="maintenanceRemindFrequency" label-width="80px" v-if="createForm.isMaintenance == '是'" >
                        <!-- {{ '每' }} -->
                        <el-popover v-model="cronmaintenance4">
                            <cron @change="changemaintenance($event,'2')" @close="cronmaintenance4=false" i18n="cn"></cron>
                            <el-input clearable style="width: 130px;margin: 0 3px 0 6px;" slot="reference" @click="cronmaintenance4=true" v-model="createForm.maintenanceRemindFrequency" placeholder="请输入定时策略"></el-input>
                        </el-popover> {{ '或' }}    
                        <!-- maintenanceCumulativeNumber 保养积累次数  -->
                        <el-input clearable style="width: 80px;margin: 0 3px 0 6px;" v-model.trim="createForm.maintenanceRemindUpperFrequencyLimit" class="ul-item" /> {{ '%邮件提醒' }}
                    </el-form-item>
                </div>
                </el-col>
                <el-col :span="5">
                <div style="height: 45px;">
                    <!-- spotJobNumber 人员工号    spotUserMail  邮箱 -->
                    <el-form-item label="点检人员" prop="spotUserName" v-if="createForm.isSpot == '是'" >
                        <div style="display: flex;">
                            <el-select filterable v-model="createForm.spotUserName" placeholder="姓名" @change="changeNamePC($event,'1')" @focus="getuserList" class="ul-item">
                                <el-option :value="item.userName" :label="item.userName" v-for="(item,index) in this.userList" :key="index"/>
                            </el-select>
                            <el-select filterable v-model="createForm.spotJobNumber" placeholder="工号" @change="changejobNumberPC($event,'1')" @focus="getuserList" class="ul-item">
                                <el-option :value="item.jobNumber" :label="item.jobNumber" v-for="(item,index) in this.userList" :key="index"/>
                            </el-select>
                        </div>
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <!-- verifyJobNumber 人员工号    verifyUserMail  邮箱 -->
                    <el-form-item label="校验人员" prop="verifyUserName" v-if="createForm.isVerify == '是'" >
                        <div style="display: flex;">
                            <el-select filterable v-model="createForm.verifyUserName" placeholder="姓名" @change="changeNamePC($event,'2')" @focus="getuserList" class="ul-item">
                                <el-option :value="item.userName" :label="item.userName" v-for="(item,index) in this.userList" :key="index"/>
                            </el-select>
                            <el-select filterable v-model="createForm.verifyJobNumber" placeholder="工号" @change="changejobNumberPC($event,'2')" @focus="getuserList" class="ul-item">
                                <el-option :value="item.jobNumber" :label="item.jobNumber" v-for="(item,index) in this.userList" :key="index"/>
                            </el-select>
                        </div>
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <!-- externalSchoolJobNumber 人员工号    externalSchoolUserMail  邮箱 -->
                    <el-form-item label="外校人员" prop="externalSchoolUserName" v-if="createForm.isExternalSchool == '是'" >
                        <div style="display: flex;">
                            <el-select filterable v-model="createForm.externalSchoolUserName" placeholder="姓名" @change="changeNamePC($event,'3')" @focus="getuserList" class="ul-item">
                                <el-option :value="item.userName" :label="item.userName" v-for="(item,index) in this.userList" :key="index"/>
                            </el-select>
                            <el-select filterable v-model="createForm.externalSchoolJobNumber" placeholder="工号" @change="changejobNumberPC($event,'3')" @focus="getuserList" class="ul-item">
                                <el-option :value="item.jobNumber" :label="item.jobNumber" v-for="(item,index) in this.userList" :key="index"/>
                            </el-select>
                        </div>
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <!-- maintenanceJobNumber 人员工号    maintenanceUserMail  邮箱 -->
                    <el-form-item label="保养人员" prop="maintenanceUserName" v-if="createForm.isMaintenance == '是'" >
                        <div style="display: flex;">
                            <el-select filterable v-model="createForm.maintenanceUserName" placeholder="姓名" @change="changeNamePC($event,'4')" @focus="getuserList" class="ul-item">
                                <el-option :value="item.userName" :label="item.userName" v-for="(item,index) in this.userList" :key="index"/>
                            </el-select>
                            <el-select filterable v-model="createForm.maintenanceJobNumber" placeholder="工号" @change="changejobNumberPC($event,'4')" @focus="getuserList" class="ul-item">
                                <el-option :value="item.jobNumber" :label="item.jobNumber" v-for="(item,index) in this.userList" :key="index"/>
                            </el-select>
                        </div>
                    </el-form-item>
                </div>
            </el-col>
            <!-- <el-col :span="2">
                <div style="height: 45px;">
                    <el-form-item label="邮件提醒" prop="aMail" v-if="createForm.isSpot == '是'" >
                        <el-switch @change="changeMail($event,'1')" v-model="createForm.aMail" active-value="是" inactive-value="否" />
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <el-form-item label="邮件提醒" prop="bMail" v-if="createForm.isVerify == '是'" >
                        <el-switch  @change="changeMail($event,'2')" v-model="createForm.bMail" active-value="是" inactive-value="否" />
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <el-form-item label="邮件提醒" prop="cMail" v-if="createForm.isExternalSchool == '是'" >
                        <el-switch  @change="changeMail($event,'3')" v-model="createForm.cMail" active-value="是" inactive-value="否" />
                    </el-form-item>
                </div>
                <div style="height: 45px;">
                    <el-form-item label="邮件提醒" prop="dMail" v-if="createForm.isMaintenance == '是'" >
                        <el-switch  @change="changeMail($event,'4')" v-model="createForm.dMail" active-value="是" inactive-value="否" />
                    </el-form-item>
                </div>
            </el-col> -->
          </el-row>
          <el-row :gutter="0">
            <el-col :span="3">
                <el-form-item label="报废审核" prop="retirementAudit" label-width="80px" >
                  <el-switch  v-model="createForm.retirementAudit" active-value="是" inactive-value="否" />
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="生命周期天数" prop="retirementUpperLimitDate" >
                  <el-input clearable v-model.trim="createForm.retirementUpperLimitDate" class="ul-item" /> {{ '&nbsp;天' }}
                </el-form-item>
            </el-col>
            <el-col :span="5">
                <el-form-item label="生命周期次数" prop="retirementUpperLimitNumber" >
                  <el-input clearable v-model.trim="createForm.retirementUpperLimitNumber" class="ul-item" /> {{ '&nbsp;次' }}
                </el-form-item>
            </el-col>
            <el-col :span="7">
                <!-- retirementJobNumber 管理人员工号   retirementUserMail  邮箱 -->
                <el-form-item label="管理人员" prop="retirementUserName" >
                    <div style="display: flex;">
                            <el-select filterable v-model="createForm.retirementUserName" placeholder="姓名" @change="changeNamePC($event,'5')" @focus="getuserList" class="ul-item">
                                <el-option :value="item.userName" :label="item.userName" v-for="(item,index) in this.userList" :key="index"/>
                            </el-select>
                            <el-select filterable v-model="createForm.retirementJobNumber" placeholder="工号" @change="changejobNumberPC($event,'5')" @focus="getuserList" class="ul-item">
                                <el-option :value="item.jobNumber" :label="item.jobNumber" v-for="(item,index) in this.userList" :key="index"/>
                            </el-select>
                        </div>
                </el-form-item>
            </el-col>
            <!-- <el-col :span="3">
                <el-form-item label="邮件提醒" prop="eMail" >
                  <el-switch @change="changeMail($event,'5')" v-model="createForm.eMail" active-value="是" inactive-value="否" />
                </el-form-item>
            </el-col> -->
          </el-row>
            <div style="display: flex;">
                <!-- <el-form-item label="条码" prop="materialCode" >
                    <el-input v-model.trim="createForm.materialCode" class="ul-item" style="width: 200px;"/>
                </el-form-item> -->
                <el-form-item label="备注" prop="remark" label-width="80px" >
                    <el-input clearable type="textarea" v-model.trim="createForm.remark" class="ul-item" style="width: 300px;"/>
                </el-form-item>
            </div>
        </el-form>

        <!-- 公共底部 -->
        <div slot="footer" class="dialog-footer">
            <el-button @click="showAdd = false">取 消</el-button>
            <el-button
            type="primary"
            @click="addplate('createForm')">确 认</el-button>
        </div>
    </el-dialog>

    <div class="filter-container">
      <!-- style="width: 150px;margin-right:15px;" -->
        <el-input
            @keyup.enter.native="getData"
            clearable
            style="margin-right: 10px"
            :style="{ width: inputWid(param.texture) }"
            v-model.trim="param.facilityBarcode"
            placeholder="请输入资源条码"
        ></el-input>

        <el-select
            v-model.number="param.facilityBarcodeType1"
            style="width: 130px;margin-right:10px;"
            class="ul-item"
            filterable
            clearable
            placeholder="资源大类"
            @focus="BarcodeType('大类')">
            <el-option
                v-for="(item,index) in barcodeType1List"
                :key="index"
                :label="item.facilityBarcodeName"
                :value="item.facilityBarcodeName">
            </el-option>
        </el-select>

        <el-select
        v-model.trim="param.facilityBarcodeType2"
            style="width: 130px;margin-right:10px;"
            class="ul-item"
            filterable
            clearable
            placeholder="资源小类"
            @focus="BarcodeType('小类')">
            <el-option
                v-for="(item,index) in barcodeType2List"
                :key="index"
                :label="item.facilityBarcodeName"
                :value="item.facilityBarcodeName">
            </el-option>
        </el-select>

        
        <el-input
        @keyup.enter.native="getData"
        clearable
        style="width: 130px;margin-right:10px;"
        v-model.trim="param.facilityCoding"
        placeholder="资源名称"
        ></el-input>
        
        <el-select
            style="width: 130px;margin-right:10px;"
            v-model.trim="param.facilityBarcodeType3"
            placeholder="规格型号"
            class="ul-item"
            filterable
            clearable
            @focus="BarcodeType('规格')">
            <el-option
                v-for="(item,index) in barcodeType3List"
                :key="index"
                :label="item.facilityBarcodeName"
                :value="item.facilityBarcodeName">
            </el-option>
        </el-select>

        <!-- <el-input
            @keyup.enter.native="getData"
            clearable
            style="width: 130px;margin-right:10px;"
            v-model.trim="param.facilityBarcodeType3"
            placeholder="规格型号"
        ></el-input> -->
        
        <!-- <el-input
            @keyup.enter.native="getData"
            clearable
            style="width: 130px;margin-right:10px;"
            v-model.trim="param.resourceSource"
            placeholder="资源来源"
        ></el-input> -->

        <el-select style="width: 130px;margin-right:10px;" clearable v-model="param.resourceSource" placeholder="资源来源" class="ul-item">
            <el-option v-for="(item,index) in propertyList" :key="index" :label="item" :value="item" />
        </el-select>

        <el-select style="width: 130px;margin-right:10px;" clearable filterable v-model="param.workCenter" placeholder="请选择工作中心" @change="changeworkCenter" @focus="getCenterList" class="ul-item">
          <el-option :value="item" :label="item" v-for="(item,index) in this.centerList.data" :key="index"/>
        </el-select>

        <el-select
              v-model="param.isDelete"
              clearable
              placeholder="状态"
              style="width: 130px;margin-right:10px;margin-top:7px">
              <el-option
              :value="item"
              :label="item"
              v-for="(item,index) of this.statusList"
              :key="index"/>
          </el-select>

          <el-date-picker
          v-model="dateOptions"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          format="yyyy-MM-dd HH:mm:ss"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          style="margin-right:10px;">
        </el-date-picker>

        <el-button type="primary" v-waves icon="el-icon-search" @click="getData">搜索</el-button>
        <el-button
            type="button"
            v-waves
            class="el-button el-button--warning"
            @click="cancelSubmit"
        >
        重置</el-button>
    
    </div>

    <!-- table 表格 -->
    <el-table  :data="tableInfo" v-loading="loadingList" element-loading-text="给我一首歌的时间" stripe border fit highlight-current-row style="width: 100%;margin-top:15px;">
      <el-table-column  label="序号" type="index" align="center" width="80px"/>
      <el-table-column label="条码"  prop="facilityBarcode" align="center" width="130px"/>
      <el-table-column label="大类"  prop="facilityBarcodeType1" align="center"/>
      <el-table-column label="小类"  prop="facilityBarcodeType2" align="center"/>
      <el-table-column label="规格型号"  prop="facilityBarcodeType3" align="center"/>
      <el-table-column label="名称"  prop="facilityName" align="center"/>
      <el-table-column label="资源编码"  prop="facilityCoding" align="center"/>
      <el-table-column label="工作中心"  prop="workCenter" align="center"/>
      <el-table-column label="库房位置"  prop="warehouseLocation" align="center"/>
      <el-table-column label="来源属性"  prop="resourceSource" align="center"/>
      <el-table-column label="当前状态"  prop="type" align="center"/>
      <el-table-column label="位置"  prop="lendingPosition" align="center"/>
      <el-table-column label="责任人"  prop="personInChargeUserName" align="center"/>
      <el-table-column label="管理员"  prop="userName" align="center"/>
      <el-table-column label="验收记录"  prop="inspectionReport" align="center"/>
      <el-table-column label="备注"  prop="remark" align="center"/>
      <el-table-column label="出入库审核"  prop="accessAudit" align="center"/>
      <el-table-column label="点检审核"  prop="spotAudit" align="center"/>
      <el-table-column label="是否点检"  prop="isSpot" align="center"/>
      <el-table-column label="点检频次"  prop="spotFrequency" align="center"/>
      <el-table-column label="点检人员"  prop="spotUserName" align="center"/>
      <el-table-column label="邮件提醒"  prop="spotUserMail" align="center"/>
      <el-table-column label="最近点检日期"  prop="spotTime" align="center"/>
      <el-table-column label="校验审核"  prop="verifyAudit" align="center"/>
      <el-table-column label="是否校验"  prop="isVerify" align="center"/>
      <el-table-column label="校验频次"  prop="verifyFrequency" align="center"/>
      <el-table-column label="校验人员"  prop="verifyUserName" align="center"/>
      <el-table-column label="邮件提醒"  prop="verifyUserMail" align="center"/>
      <el-table-column label="最近校验日期"  prop="verifyTime" align="center"/>
      <el-table-column label="外校审核"  prop="externalSchoolAudit" align="center"/>
      <el-table-column label="是否点检"  prop="isExternalSchool" align="center"/>
      <el-table-column label="外校频次"  prop="externalSchoolFrequency" align="center"/>
      <el-table-column label="外校人员"  prop="externalSchoolUserName" align="center"/>
      <el-table-column label="邮件提醒"  prop="externalSchoolUserMail" align="center"/>
      <el-table-column label="最近外校日期"  prop="externalSchoolTime" align="center"/> 
      <el-table-column label="保养审核"  prop="maintenanceAudit" align="center"/>
      <el-table-column label="是否保养"  prop="isMaintenance" align="center"/>
      <el-table-column label="保养频次"  prop="maintenanceFrequency" align="center"/>
      <el-table-column label="保养人员"  prop="maintenanceUserName" align="center"/>
      <el-table-column label="邮件提醒"  prop="maintenanceUserMail" align="center"/>
      <el-table-column label="最近保养日期"  prop="maintenanceTime" align="center"/>
      <el-table-column label="报废审核"  prop="retirementAudit" align="center"/>
      <el-table-column label="生命周期时间(天)"  prop="retirementUpperLimitDate" align="center"/>
      <el-table-column label="生命周期次数(次)"  prop="retirementUpperLimitNumber" align="center"/>
      <el-table-column label="审核人员"  prop="retirementUserName" align="center"/>
      <el-table-column label="邮件提醒"  prop="retirementUserMail" align="center"/>
      <el-table-column label="报废日期"  prop="retirementTime" align="center"/>
      <el-table-column label="生产或购置日期"  prop="facilityProductionDate" align="center"/>
      <el-table-column label="注册建档日期"  prop="createTime" align="center"/>
      <el-table-column label="操作" fixed="right" align="center" width="280">
            <template slot-scope="scope" >
                <div class="fx" style="display: flex">
                    <!-- <el-button size="mini" type="warning" @click="handleEdit(scope.row)">停用</el-button> -->
                    <el-button size="mini" type="success" @click="handlePrint(scope.row)">打印</el-button>
                    <el-button size="mini" type="primary" @click="handleEdit(scope.row)">修改</el-button>
                    <el-button
                        icon="el-icon-delete"
                        class="el-button el-button--danger"
                        style="font-size: 15px;"
                        @click="handleDelete(scope.row,scope.$index)"
                    >   </el-button>
                </div>
            </template>
      </el-table-column>
    </el-table>

   
   <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.page"
        :page-sizes="[5,10, 20, 30, 40, 100, 300, 500]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>

    <el-divider></el-divider>
    <!-- <h1>vue-cron</h1>
        <el-popover v-model="cronPopover">
            <cron @change="changeCron" @close="cronPopover=false" i18n="cn"></cron>
            <el-input slot="reference" @click="cronPopover=true" v-model="cron" placeholder="请输入定时策略"></el-input>
        </el-popover> -->
    <el-button style="margin-right: 10px" type="success" size="small" @click="hExportExcel">导出数据Excel</el-button>
  </div>
</template>

<script>
import { facilitySel,historyLenthins,historyLenthdel,addfacility,updfacility,delfacility,printlate,selbarcodeType,getNextExecTime } from "@/api/processRoute"
import { getCenter } from '../../api/workSection.js'
import { searchWorkers } from '../../api/chargingData.js'
import { cron } from 'vue-cron'
export default {
    template: '<cron/>',
    components: { cron },
    name: 'registrationFile',
    data () {
        return {
            title: '新增',
            cron:'',
            cronspot: false,        // 点检表达式弹框
            cronspot1: false,
            cronverify: false,      // 校验
            cronverify2: false,
            cronexternal: false,    // 外校
            cronexternal3: false,
            cronmaintenance: false, // 保养
            cronmaintenance4: false,
            listQuery: {
                page: 1,                                    //页码
                limit: 10                                   //每页多少条记录
            },
            param: {
                materialCode:'',
                isDelete: '未删除',
            },
            total: 0,                                      //数据的总数
            tableInfo: [],
            loadingList: false,
            loading: false,
            createForm: {},
            updForm: {},
            statusList: ['未删除','已删除'],
            dateOptions: this.getNowTime(),
            pickerOptions: {                            // 选择时间范围
              shortcuts: [{
                text: '最近一周',
                onClick(picker) {
                  const end = new Date();
                  const start = new Date();
                  start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                  picker.$emit('pick', [start, end]);
                }
              }, {
                text: '最近一个月',
                onClick(picker) {
                  const end = new Date();
                  const start = new Date();
                  start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                  picker.$emit('pick', [start, end]);
                }
              }, {
                text: '最近三个月',
                onClick(picker) {
                  const end = new Date();
                  const start = new Date();
                  start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                  picker.$emit('pick', [start, end]);
                }
              }]
            },
            // 表单校验
            addRules: {
                facilityBarcodeType1: [
                    { required: true, message: "资源大类不能为空", trigger: "blur" },
                ],
                facilityBarcodeType2: [
                    { required: true, message: "资源小类不能为空", trigger: "blur" },
                ],
                facilityBarcodeType3: [
                    { required: true, message: "资源规格不能为空", trigger: "blur" },
                ],
                facilityName: [
                    { required: true, message: "资源名称不能为空", trigger: "change" },
                ],
                resourceSource: [
                    { required: true, message: "来源属性不能为空", trigger: "change" },
                ],
                workCenter: [
                    { required: true, message: "工作中心不能为空", trigger: "change" },
                ],
                warehouseLocation: [
                    { required: true, message: "库房位置不能为空", trigger: "change" },
                ],
                userName: [
                    { required: true, message: "管理员不能为空", trigger: "change" },
                ],
                accessAudit: [
                    { required: true, message: "出入库审核不能为空", trigger: "change" },
                ],
                facilityProductionDate: [
                    { required: true, message: "生产或购置日期不能为空", trigger: "change" },
                ],
                spotAudit: [
                    { required: true, message: "点检审核不能为空", trigger: "change" },
                ],
                verifyAudit: [
                    { required: true, message: "校验审核不能为空", trigger: "change" },
                ],
                externalSchoolAudit: [
                    { required: true, message: "外校审核不能为空", trigger: "change" },
                ],
                maintenanceAudit: [
                    { required: true, message: "保养审核不能为空", trigger: "change" },
                ],
                retirementAudit: [
                    { required: true, message: "报废审核不能为空", trigger: "change" },
                ],
                retirementUpperLimitDate: [
                    { required: true, message: "生命周期天数不能为空", trigger: "change" },
                ],
                retirementUpperLimitNumber: [
                    { required: true, message: "生命周期次数不能为空", trigger: "change" },
                ],
                spotUserName: [
                    { required: true, message: "点检人员不能为空", trigger: "change" },
                ],
                verifyUserName: [
                    { required: true, message: "校验人员不能为空", trigger: "change" },
                ],
                externalSchoolUserName: [
                    { required: true, message: "外校人员不能为空", trigger: "change" },
                ],
                maintenanceUserName: [
                    { required: true, message: "保养人员不能为空", trigger: "change" },
                ],
                retirementUserName: [
                    { required: true, message: "管理人员不能为空", trigger: "change" },
                ],
            },
            getHttpHeader: {                    //上传文件的头
                Authorization: '',              //传输文件的token
                CHECK_USER_VALUE: 'GOLWAY',
                CHECK_PASSWORD_VALUE: '8D4DD3F80CEB6149329FDBD590B164F1'
            },
            showAdd: false,
            showupd: false,
            userInfo: this.$store.state.user.userInfo,
            centerList: {data:[]},                            // 工作中心列表
            userList: [],                                      // 员工列表
            // 库房位置列表
            placeList: ['EMS工具房','EMS装备库','数控模具库','数控工装检具库','焊接工装检具库','喷涂工装检具库','装配工装库','装配检具库'],
            // 来源属性列表
            propertyList: ['外购','自制','租赁','客供'],
            fileBool: true,         // 上传文件控制按钮
            barcodeType1List: [],
            barcodeType2List: [],
            barcodeType3List: []
        }
    },
    computed: {
      inputWid() {
        return function (value) {
            if(!value || (value.length <= 10)){
              return '150px'
            } else {
              return (150 + (String(value).length-10)*6) + 'px'
            }
        }
      }
    },
    methods: {
        // 获取个人信息
      async getuserList(){
        let query = {page:1,limit:9999}
        const {data} = await searchWorkers(query)
        this.userList = data.records
        },
        // 获取工作中心
      async getCenterList() {   
        let query = {}
        const data = await getCenter(query)
        this.centerList = data
      },
       // 邮件改变
      async changeMail(e,id){
        console.log(e)
        if(id == '1'){
            console.log(this.createForm.spotUserMail)
            if(!this.createForm.spotUserMail || this.createForm.spotUserMail == 'null') {
                let query = {jobNumber:this.createForm.spotJobNumber,username:this.createForm.spotUserName ,page:1,limit:9999}
                const {data} = await searchWorkers(query)
                if(data.records.length || !data.records[0].mail){ 
                    this.createForm.aMail = '0'
                    return this.$message.warning('该员工没有邮箱，请录入邮箱!') 
                }else {
                    this.createForm.spotUserMail = data.records[0].mail
                }
            }
        } else if(id == '2'){
            if(!this.createForm.verifyUserMail) {
                this.createForm.bMail = '0'
                return this.$message.warning('该员工没有邮箱，请录入邮箱!')
            }
        } else if(id == '3'){
            if(!this.createForm.externalSchoolUserMail) {
                this.createForm.cMail = '0'
                return this.$message.warning('该员工没有邮箱，请录入邮箱!')
            }
        } else if(id == '4'){
            if(!this.createForm.maintenanceUserMail) {
                this.createForm.dMail = '0'
                return this.$message.warning('该员工没有邮箱，请录入邮箱!')
            }
        } else if(id == '5'){
            if(!this.createForm.retirementUserMail) {
                this.createForm.eMail = '0'
                return this.$message.warning('该员工没有邮箱，请录入邮箱!')
            }
        }
      },
      changeName(e){
        if(!e) return this.createForm.jobNumber = ''
        this.userList.forEach(item => {
            if(item.userName == e){
                this.createForm.jobNumber = item.jobNumber
            }
        })
      },
      changejobNumber(e){
        if(!e) return this.createForm.userName = ''
        this.userList.forEach(item => {
            if(item.jobNumber == e){
                this.createForm.userName = item.userName
            }
        })
      },
        // 频次姓名发生改变
      changeNamePC(e,id){
        this.userList.forEach(item => {
            if(item.userName == e){
                if(id == '1') {
                    this.createForm.aMail = '0'
                    this.createForm.spotJobNumber = item.jobNumber
                    if(item.mail){
                        this.createForm.spotUserMail = item.mail
                    } else {
                        return this.$message.warning('该员工没有邮箱，请录入邮箱!')
                    }
                } else if(id == '2') {
                    this.createForm.bMail = '0'
                    this.createForm.verifyJobNumber = item.jobNumber
                    if(item.mail){
                        this.createForm.verifyUserMail = item.mail
                    } else {
                        return this.$message.warning('该员工没有邮箱，请录入邮箱!')
                    }
                } else if(id == '3') {
                    this.createForm.cMail = '0'
                    this.createForm.externalSchoolJobNumber = item.jobNumber
                    if(item.mail){
                        this.createForm.externalSchoolUserMail = item.mail
                    } else {
                        return this.$message.warning('该员工没有邮箱，请录入邮箱!')
                    }
                } else if(id == '4') {
                    this.createForm.dMail = '0'
                    this.createForm.maintenanceJobNumber = item.jobNumber
                    if(item.mail){
                        this.createForm.maintenanceUserMail = item.mail
                    } else {
                        return this.$message.warning('该员工没有邮箱，请录入邮箱!')
                    }
                } else if(id == '5') {
                    this.createForm.eMail = '0'
                    this.createForm.retirementJobNumber = item.jobNumber
                    if(item.mail){
                        this.createForm.retirementUserMail = item.mail
                    } else {
                        return this.$message.warning('该员工没有邮箱，请录入邮箱!')
                    }
                }
            }
        })
      },
      // 频次工号发生改变
      changejobNumberPC(e,id){
        this.userList.forEach(item => {
            if(item.jobNumber == e){
                if(id == '1') {
                    this.createForm.aMail = '0'
                    this.createForm.spotUserName = item.userName
                    if(item.mail){
                        this.createForm.spotUserMail = item.mail
                    } else {
                        return this.$message.warning('该员工没有邮箱，请录入邮箱!')
                    }
                } else if(id == '2') {
                    this.createForm.bMail = '0'
                    this.createForm.verifyUserName = item.userName
                    if(item.mail){
                        this.createForm.verifyUserMail = item.mail
                    } else {
                        return this.$message.warning('该员工没有邮箱，请录入邮箱!')
                    }
                } else if(id == '3') {
                    this.createForm.cMail = '0'
                    this.createForm.externalSchoolUserName = item.userName
                    if(item.mail){
                        this.createForm.externalSchoolUserMail = item.mail
                    } else {
                        return this.$message.warning('该员工没有邮箱，请录入邮箱!')
                    }
                } else if(id == '4') {
                    this.createForm.dMail = '0'
                    this.createForm.maintenanceUserName = item.userName
                    if(item.mail){
                        this.createForm.maintenanceUserMail = item.mail
                    } else {
                        return this.$message.warning('该员工没有邮箱，请录入邮箱!')
                    }
                } else if(id == '5') {
                    this.createForm.eMail = '0'
                    this.createForm.retirementUserName = item.userName
                    if(item.mail){
                        this.createForm.retirementUserMail = item.mail
                    } else {
                        return this.$message.warning('该员工没有邮箱，请录入邮箱!')
                    }
                }
            }
        })
      },
      // 点检表达式改变
      async changespot(val,id){
        let arr = val.split(" ");
        arr.pop()
        if(id == '1'){
            this.createForm.spotFrequency=arr.join(" ")
            this.reminder5(this.createForm.spotFrequency)
        } else {
            this.createForm.spotRemindFrequency=arr.join(" ")
            this.reminder5(this.createForm.spotRemindFrequency)
        }
    },
    // 进5次的提醒
    async reminder5(e){
        let query = {
          numTimes: 5,
          cronExpression: e
        }
        const res = await getNextExecTime(query)
         let messageContent = ''
        res.data.forEach(item => {  
        // 将每个项目添加到 messageContent 字符串中，并在每个项目后添加换行符  
        messageContent += `<div>${item}</div>`;  
      });
      // 去除字符串末尾的换行符（如果有的话）  
      if (messageContent.endsWith('\n')) {      
        messageContent = messageContent.slice(0, -1);  
      }  
        this.$message({     
          dangerouslyUseHTMLString: true,
          message: `<div>近五次的执行结果:</div>${messageContent}`,
          type: 'success',
          duration: 5000
        });
    },
    changeworkCenter(){
        this.createForm.facilityBarcodeType1 = ''
        this.createForm.facilityBarcodeType2 = ''
        this.createForm.facilityBarcodeType3 = ''
    },
    changeType1(e){
        this.barcodeType1List.forEach(item => {
            if(item.facilityBarcodeName == e){
                this.createForm.workCenter = item.workCenter
            }
        })
    },
    changeType2(e){
        this.barcodeType2List.forEach(item => {
            if(item.facilityBarcodeName == e){
                this.createForm.workCenter = item.workCenter
            }
        })
    },
    changeType3(e){
        this.barcodeType3List.forEach(item => {
            if(item.facilityBarcodeName == e){
                this.createForm.workCenter = item.workCenter
            }
        })
    },
    async getBarcodeType(type) {
            if(!this.createForm.workCenter) return this.$message.warning('请先选择工作中心')
            let query = {           
                workCenter: this.createForm.workCenter,  
                facilityBarcodeType: type,
                page: 1,
                limit: 10000
            }
            let data = await selbarcodeType(query)
            let errmsg = data.msg
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errmsg)
            if(type == '大类'){
                this.barcodeType1List = data.data.records
            } else if(type == '小类') {
                this.barcodeType2List = data.data.records
            } else if(type == '规格') {
                this.barcodeType3List = data.data.records
            }
        },
        // 查询页
        async BarcodeType(type) {
            let query = {           
                facilityBarcodeType: type,
                page: 1,
                limit: 10000
            }
            let data = await selbarcodeType(query)
            let errmsg = data.msg
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errmsg)
            if(type == '大类'){
                this.barcodeType1List = data.data.records
            } else if(type == '小类') {
                this.barcodeType2List = data.data.records
            } else if(type == '规格') {
                this.barcodeType3List = data.data.records
            }
        },
    changeverify(val,id){
        let arr = val.split(" ");
        arr.pop()
        if(id == '1'){
            this.createForm.verifyFrequency=arr.join(" ")
            this.reminder5(this.createForm.verifyFrequency)
        } else {
            this.createForm.verifyRemindFrequency=arr.join(" ")
            this.reminder5(this.createForm.verifyRemindFrequency)
        }
      },
      changeexternal(val,id){
        let arr = val.split(" ");
        arr.pop()
        if(id == '1'){
            this.createForm.externalSchoolFrequency=arr.join(" ")
            this.reminder5(this.createForm.externalSchoolFrequency)
        } else {
            this.createForm.externalSchoolRemindFrequency=arr.join(" ")
            this.reminder5(this.createForm.externalSchoolRemindFrequency)
        }
      },
      changemaintenance(val,id){
        let arr = val.split(" ");
        arr.pop()
        if(id == '1'){
            this.createForm.maintenanceFrequency=arr.join(" ")
            this.reminder5(this.createForm.maintenanceFrequency)
        } else {
            this.createForm.maintenanceRemindFrequency=arr.join(" ")
            this.reminder5(this.createForm.maintenanceRemindFrequency)
        }
      },
       // 上传PDF文档成功回调函数
       handlePdfSuccess(response) {
            this.createForm.inspectionReport = response.results
            console.log(11,this.createForm.inspectionReport)
        },
         // 移除pdf
         async removePdf(file) {
            this.fileBool = true
            return this.createForm.inspectionReport = ''
            // const {data} = await deleteFiles({image: this.form.pdfUrl})
            // this.form.pdfUrl = ''
            // console.log(file,'removePdf')
        },
        pdfRemove(e){
            if(e.status == 'fail') return this.$message.error("文件上传失败!")
            else if(e.status == 'success'){ 
                this.fileBool = false
                return this.$message.success("文件上传成功!")
            }
        },
        // 文件上传之前的函数，将token传入头中
        beforeFilsUpload(file) {
            this.getHttpHeader.Authorization = this.dealCookie()
        },
         // cookies的处理函数
         dealCookie() {
            const strcookie = document.cookie                     //获取cookie字符串
            const arrcookie = strcookie.split("; ")               //分割
            for ( var i = 0; i < arrcookie.length; i++) {
                const arr = arrcookie[i].split("=")
                if (arr[0] == "agent_Authorization") {
                    return arr[1]
                }
            }
            return ""
        },
         //初始默认执行(重点)，返回日期格式YYYY-MM-DD HH:MM:SS
         getNowTime() {
        let dateTime = +new Date()+8*3600*1000
        const start = new Date(dateTime - 3600 * 1000 * 24 * 7)
            .toISOString()
            .replace('T', ' ')
            .split('.')[0]
            // .substring(0,10) //默认开始时间7天前
        const end = new Date(dateTime)
            .toISOString()
            .replace('T', ' ')
            .split('.')[0]
            // .substring(0,10)//默认结束时间当前时间
        console.log([start, end])
        return [start, end]
        },
        getData(){
          this.listQuery.page = 1
          this.listQuery.limit = 10
          this.handleFilter()
        },
        async handleFilter() {
            this.loadingList = true
            let query = Object.assign({},this.listQuery,this.param)
            this.param.isDelete == '未删除' ? query.isDelete = 0 : query.isDelete = 1
            if(this.dateOptions) {
              if(this.dateOptions.length) {
                  query.strTime = this.dateOptions[0]
                  query.endTime = this.dateOptions[1]
              }
            }
            let data = await facilitySel(query)
            let errmsg = data.msg
            this.loadingList = false
            if(data.code != '1') return this.$message.error(errmsg)
            this.total = data.data.total
            this.tableInfo = data.data.records
        },
        // table表单下方的页码组件改变每页显示的数据条数
        handleSizeChange(val) {
          this.listQuery.limit = val
          this.handleFilter()
        },
        // table表单下方的页码组件改变页面
        handleCurrentChange(val) {
          this.listQuery.page = val
          this.handleFilter()
        },
        transformDat(res) {
          const mapInfo = {
            facilityBarcode: '条码',
            facilityBarcodeType1: '大类',
            facilityBarcodeType2: '小类',
            facilityBarcodeType3: '规格型号',
            facilityName: '名称',
            facilityCoding: '资源编码',
            workCenter: '工作中心',
            warehouseLocation: '库房位置',
            resourceSource: '来源属性',
            type: '当前状态',
            lendingPosition: '位置',
            personInChargeUserName: '责任人',
            userName: '管理员',
            inspectionReport: '验收记录',
            remark: '备注',
            accessAudit: '出入库审核',
            spotAudit: '点检审核',
            isSpot: '是否点检',
            spotFrequency: '点检频次',
            spotUserName: '点检人员',
            spotUserMail: '邮件提醒',
            spotTime: '最近点检日期',
            verifyAudit: '校验审核',
            isVerify: '是否校验',
            verifyFrequency: '校验频次',
            verifyUserName: '校验人员',
            verifyUserMail: '邮件提醒',
            verifyTime: '最近校验日期',
            externalSchoolAudit: '外校审核',
            isExternalSchool: '是否点检',
            externalSchoolFrequency: '外校频次',
            externalSchoolUserName: '外校人员',
            externalSchoolUserMail: '邮件提醒',
            externalSchoolTime: '最近外校日期',
            maintenanceAudit: '保养审核',
            isMaintenance: '是否保养',
            maintenanceFrequency: '保养频次',
            maintenanceUserName: '保养人员',
            maintenanceUserMail: '邮件提醒',
            maintenanceTime: '最近保养日期',
            retirementAudit: '报废审核',
            retirementUpperLimitDate: '生命周期时间(天)',
            retirementUpperLimitNumber: '生命周期次数(次)',
            retirementUserName: '审核人员',
            retirementUserMail: '邮件提醒',
            retirementTime: '报废日期',
            facilityProductionDate: '生产或购置日期',
            createTime: '注册建档日期',
          }
          // 对data进行格式化
          // 取出所有的属性名
          const props = Object.keys(res[0]) // ['id','']
          // 将属性名从英文转为中文
          const header = props.map(zhkey => mapInfo[zhkey])
          console.log('中文的表头', header)
          // const data=[['xxxx','总裁办'，'13800000']]
          const data = res.map(obj => Object.values(obj))
          return { header, data }
        },
        // 导出excel
        async hExportExcel() {
          this.loading = true
          let query = Object.assign({},this.listQuery,this.param)
          query.page = 1
          query.limit = 10000
          this.param.isDelete == '未删除' ? query.isDelete = 0 : query.isDelete = 1
          if(this.dateOptions) {
              if(this.dateOptions.length) {
                  query.strTime = this.dateOptions[0]
                  query.endTime = this.dateOptions[1]
              }
            }
          let arr = await facilitySel(query)
          if(arr.code != '1'){
            this.loading = false
            return this.$message.error(errmsg)
          }
          const { header, data } = this.transformDat(this.setSort(arr.data.records))
          import('@/vendor/Export2Excel').then(excel => {
            // excel表示导入的模块对象
            console.log(excel)
            excel.export_json_to_excel({
            header, // 表头 必填
            data, // 具体数据 必填
            filename: '注册建档', // 文件名称
            autoWidth: true, // 宽度是否自适应
            bookType: 'xlsx' // 生成的文件类型
            })
          })
          this.loading = false
        },
        // 排序函数
        setSort(arr){
          let newArr = JSON.parse(JSON.stringify(arr))
          let arr1 = []
          newArr.forEach((item,index)=>{
            let obj = {
                facilityBarcode: item.facilityBarcode,
                facilityBarcodeType1: item.facilityBarcodeType1,
                facilityBarcodeType2: item.facilityBarcodeType2,
                facilityBarcodeType3: item.facilityBarcodeType3,
                facilityName: item.facilityName,
                facilityCoding: item.facilityCoding,
                workCenter: item.workCenter,
                warehouseLocation: item.warehouseLocation,
                resourceSource: item.resourceSource,
                type: item.type,
                lendingPosition: item.lendingPosition,
                personInChargeUserName: item.personInChargeUserName,
                userName: item.userName,
                inspectionReport: item.inspectionReport,
                remark: item.remark,
                accessAudit: item.accessAudit,
                spotAudit: item.spotAudit,
                isSpot: item.isSpot,
                spotFrequency: item.spotFrequency,
                spotUserName: item.spotUserName,
                spotUserMail: item.spotUserMail,
                spotTime: item.spotTime,
                verifyAudit: item.verifyAudit,
                isVerify: item.isVerify,
                verifyFrequency: item.verifyFrequency,
                verifyUserName: item.verifyUserName,
                verifyUserMail: item.verifyUserMail,
                verifyTime: item.verifyTime,
                externalSchoolAudit: item.externalSchoolAudit,
                isExternalSchool: item.isExternalSchool,
                externalSchoolFrequency: item.externalSchoolFrequency,
                externalSchoolUserName: item.externalSchoolUserName,
                externalSchoolUserMail: item.externalSchoolUserMail,
                externalSchoolTime: item.externalSchoolTime,
                maintenanceAudit: item.maintenanceAudit,
                isMaintenance: item.isMaintenance,
                maintenanceFrequency: item.maintenanceFrequency,
                maintenanceUserName: item.maintenanceUserName,
                maintenanceUserMail: item.maintenanceUserMail,
                maintenanceTime: item.maintenanceTime,
                retirementAudit: item.retirementAudit,
                retirementUpperLimitDate: item.retirementUpperLimitDate,
                retirementUpperLimitNumber: item.retirementUpperLimitNumber,
                retirementUserName: item.retirementUserName,
                retirementUserMail: item.retirementUserMail,
                retirementTime: item.retirementTime,
                facilityProductionDate: item.facilityProductionDate,
                createTime: item.createTime,
            }
            arr1.push(obj)
          })
          return arr1
        },
        cancelSubmit(){
            this.param = {}
            // this.listQuery.page = 1
            this.handleFilter()
        },
        alterClose(){
            if(this.title == '修改'){
                this.close()
            }
        },
        close(){
            this.showAdd = false
            this.createForm = {
                accessAudit: "否",
                externalSchoolAudit: "否",  
                isExternalSchool: "否",
                isMaintenance: "否",
                isSpot: "否",
                isVerify: "否",
                maintenanceAudit: "否",
                retirementAudit: "否",
                spotAudit: "否",
                verifyAudit: "否"
            }
            this.resetForm()
        },
        // 提交表单之前先进行验证
        addplate(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                        this.submitplate()
                } else {
                    return false
                }
            })
        },
        // 校验频次前三位不能是*号(不然频次太快)
        hasFirstThreeAsterisks(sty) {  
            let arr = sty.split(" ")
           // 检查数组长度是否足够  
           if (arr.length < 3) {  
               return true; // 如果数组长度小于3，则不可能前三个都有*号  
           }
           // 遍历前三个元素  
           for (let i = 0; i < 3; i++) {  
               // 如果任何一个元素不包含*号，则返回true  
               if (arr[i].includes('*')) {  
                   return true;  
               }  
           }
           // 如果所有检查都通过，则返回true  
           return false;  
       },
        async submitplate(){
            let query = Object.assign({},this.createForm)
            if(query.isSpot == '否'){
                delete query.spotFrequency
                delete query.spotUpperLimitNumber
                delete query.spotUserName
                delete query.spotJobNumber
                delete query.spotUserMail
                delete query.spotRemindFrequency
                delete query.spotRemindUpperFrequencyLimit
            } else {
                if(!query.spotFrequency && !query.spotUpperLimitNumber) return this.$message.warning('点检频次必须填写一个！')
                if(query.spotFrequency && !query.spotUpperLimitNumber) query.spotUpperLimitNumber = -1
                if(!query.spotFrequency && query.spotUpperLimitNumber) query.spotFrequency = null
            }
            if(query.isVerify == '否'){
                delete query.verifyFrequency
                delete query.verifyUpperLimitNumber
                delete query.verifyUserName
                delete query.verifyJobNumber
                delete query.verifyUserMail
                delete query.verifyRemindFrequency
                delete query.verifyRemindUpperFrequencyLimit
            } else {
                if(!query.verifyFrequency && !query.verifyUpperLimitNumber) return this.$message.warning('校验频次必须填写一个！')
                if(query.verifyFrequency && !query.verifyUpperLimitNumber) query.verifyUpperLimitNumber = -1
                if(!query.verifyFrequency && query.verifyUpperLimitNumber) query.verifyFrequency = null
            }
            if(query.isExternalSchool == '否'){
                delete query.externalSchoolFrequency
                delete query.externalSchoolUpperLimitNumber
                delete query.externalSchoolUserName
                delete query.externalSchoolJobNumber
                delete query.externalSchoolUserMail
                delete query.externalSchoolRemindFrequency
                delete query.externalSchoolRemindUpperFrequencyLimit
            } else {
                if(!query.externalSchoolFrequency && !query.externalSchoolUpperLimitNumber) return this.$message.warning('外校频次必须填写一个！')
                if(query.externalSchoolFrequency && !query.externalSchoolUpperLimitNumber) query.externalSchoolUpperLimitNumber = -1
                if(!query.externalSchoolFrequency && query.externalSchoolUpperLimitNumber) query.externalSchoolFrequency = null
            }
            if(query.isMaintenance == '否'){
                delete query.maintenanceFrequency
                delete query.maintenanceUpperLimitNumber
                delete query.maintenanceUserName
                delete query.maintenanceJobNumber
                delete query.maintenanceUserMail
                delete query.maintenanceRemindFrequency
                delete query.maintenanceRemindUpperFrequencyLimit
            } else {
                if(!query.maintenanceFrequency && !query.maintenanceUpperLimitNumber) return this.$message.warning('保养频次必须填写一个！')
                if(query.maintenanceFrequency && !query.maintenanceUpperLimitNumber) query.maintenanceUpperLimitNumber = -1
                if(!query.maintenanceFrequency && query.maintenanceUpperLimitNumber) query.maintenanceFrequency = null
            }
            // 是否传邮件
            if (query.aMail == '否') {
                delete query.spotUserMail
            }
            if (query.bMail == '否') {
                delete query.verifyUserMail
            }
            if (query.cMail == '否') {
                delete query.externalSchoolUserMail
            }
            if (query.dMail == '否') {
                delete query.maintenanceUserMail
            }
            if (query.eMail == '否') {
                delete query.retirementUserMail
            }
            delete query.aMail
            delete query.bMail
            delete query.cMail
            delete query.dMail
            delete query.eMail
            delete query.createTime
            delete query.updateTime
            delete query.isDelete
            if(query.spotFrequency && this.hasFirstThreeAsterisks(query.spotFrequency)) return this.$message.warning('点检频次前三位不能有*号')
            if(query.verifyFrequency && this.hasFirstThreeAsterisks(query.verifyFrequency)) return this.$message.warning('校验频次前三位不能有*号')
            if(query.externalSchoolFrequency && this.hasFirstThreeAsterisks(query.externalSchoolFrequency)) return this.$message.warning('外校频次前三位不能有*号')
            if(query.maintenanceFrequency && this.hasFirstThreeAsterisks(query.maintenanceFrequency)) return this.$message.warning('保养频次前三位不能有*号')
            if(query.spotRemindFrequency && this.hasFirstThreeAsterisks(query.spotRemindFrequency)) return this.$message.warning('提醒频次三位不能有*号')
            if(query.verifyRemindFrequency && this.hasFirstThreeAsterisks(query.verifyRemindFrequency)) return this.$message.warning('提醒频次三位不能有*号')
            if(query.externalSchoolRemindFrequency && this.hasFirstThreeAsterisks(query.externalSchoolRemindFrequency)) return this.$message.warning('提醒频次三位不能有*号')
            if(query.maintenanceRemindFrequency && this.hasFirstThreeAsterisks(query.maintenanceRemindFrequency)) return this.$message.warning('提醒频次三位不能有*号')
            console.log('query',query)
            let data
            if(this.title == '新增'){
                data = await addfacility(query)
                console.log(data)
            } else {
                data = await updfacility(query)
                console.log(data)
            }
            const errMsg = data.msg
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errMsg)
            this.$message.success(errMsg)
            this.close()
            this.handleFilter()
        },
        // 点击新增
        addclick(){
            this.title = '新增'
            this.showAdd = true
        },
         // 打印
         async handlePrint(row){
          console.log(row);
          const res = await printlate({sn:row.facilityBarcode, name: row.facilityName})
          console.log(res);
          this.$message.success('打印成功')
        },
        // 删除
        handleDelete(row,index) {
            this.$confirm('这将会永久删除该行数据，是否继续?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.delprocess(row,index)
            }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消删除'
                })
            })
        },
        async delprocess(row,index){
          let res = await delfacility({facilityBarcode: row.facilityBarcode})
          console.log(111)
          if(res.code == '500') return
          if(res.code != '1') this.$message.error(res.msg)
          this.tableInfo.splice(index,1)
          this.$message.success(res.msg)
        },
        resetForm(){
             this.$refs.createForm.resetFields();
        },
        handleEdit(row){
            console.log(row)
            this.createForm = Object.assign({},row)
            this.title = '修改'
            this.showAdd = true
        },
        // 提交表单之前先进行验证
        updprocess(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.updplate()
                } else {
                    return false
                }
            })
        },
        async updplate(){
            let query = Object.assign({},this.updForm)
            const data = await historyLenthins(query)
            const errMsg = data.msg
            if(data.code != '1') return this.$message.error(errMsg)
            this.showupd = false
            this.handleFilter()
            this.$message.success(errMsg)
        },
    },
    // 进入页面获取table信息
    mounted() {
        this.handleFilter()
    }
}
</script>

<style>

.btn-add{
    margin-bottom: 28px;
}

.ul-item{
  width: 85%;
}
</style>